package fn;

public class Subtract extends Function {
	private static final long serialVersionUID = -8356792321054437801L;

	private Function[] child;

	private Subtract(Function f0, Function f1) {
		child = new Function[] {
				f0, f1 };
	}

	public static Function create(Function f0, Function f1) {
		return new Subtract(f0, f1);
	}

	@Override
	protected Function[] child() {
		return child;
	}

	@Override
	public double evaluate(double sub) {
		return child[0].evaluate(sub) - child[1].evaluate(sub);
	}

	@Override
	public String prefix() {
		return "";
	}

	@Override
	public String infix() {
		return " - ";
	}

	@Override
	protected boolean withPar() {
		return true;
	}

	@Override
	public String postfix() {
		return "";
	}

	@Override
	protected int precedence() {
		return 1;
	}

	@Override
	public Function derivative() {
		Function out = create(child[0].derivative(), child[1].derivative());
		return out;
	}

}
